import React, {PureComponent} from 'react';

export default function lazyLoad(loading) {
    return class extends PureComponent {
        constructor(props) {
            super(props);
            this.state = {
                Com: null,
            };
        }

        componentDidMount() {
            new Promise((resolve, reject) => {
                require.ensure([], function (require) {
                    const c = loading().default;
                    console.log(c);
                    resolve(c);
                }).then((c) => {
                    this.setState({
                        Com: c
                    });
                })
            });
        }

        render() {
            const {Com} = this.state;
            return Com ? <Com /> : null;
        }
    }
}